#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int pourmilk(int x, int y, int m){
    int result = 0;
    for(int i = 0; i <= 1000; ++i){
        if(i * x > m){
            break;
        }
        else{
            for(int j = 0; j <= 1000; ++j){
                if(i * x + j * y>m){
                    break;
                }
                else{
                    if(i * x + j * y > result){
                        result = i * x + j * y;
                    }
                }
            }
        }
    }
    return result;
}

int main(int argc, char const *argv[])
{
    int x = 2;
    int y = 4;
    int m = 9;
    cout<<pourmilk(x, y, m)<<endl;
    return 0;
}
